package com.example.zx_springboot.service.iml;

import com.example.zx_springboot.entity.ZxUser;
import com.example.zx_springboot.entity.Zxcustomer;
import com.example.zx_springboot.entity.Zxloss;
import com.example.zx_springboot.mapper.ZxUserMapper;
import com.example.zx_springboot.mapper.Zx_CustomerMapper;
import com.example.zx_springboot.service.ZxCustomerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ZxCustomeriml implements ZxCustomerService {
    @Autowired
    private Zx_CustomerMapper zx_customerMapper;

    @Override
    public List<Zxcustomer> getallcustomer() {
        return zx_customerMapper.getall();
    }

    @Override
    public PageInfo findByPage(Integer pageNum, Integer pageSize, String customerName) {
        Page<Zxcustomer> page = PageHelper.startPage(pageNum, pageSize);
        //查询出来所有内容，会根据上面设置的分页参数显示
        if (customerName != "") {
            customerName = "%" + customerName + "%";
            List<Zxcustomer> zxcustomers = zx_customerMapper.SelectName(customerName);
            PageInfo<Zxcustomer> zxcustomerPageInfo = new PageInfo<>(zxcustomers);
            System.out.println("当前页" + zxcustomerPageInfo.getPageNum());
            System.out.println("总页数" + zxcustomerPageInfo.getPages());
            System.out.println("页大小" + zxcustomerPageInfo.getSize());
            System.out.println("总记录数" + zxcustomerPageInfo.getTotal());
            System.out.println("当前页数据" + zxcustomerPageInfo.getList());

            return zxcustomerPageInfo;
        } else {
            List<Zxcustomer> zxcustomers = zx_customerMapper.getall();
            PageInfo<Zxcustomer> zxcustomerPageInfo = new PageInfo<>(zxcustomers);
            System.out.println("当前页" + zxcustomerPageInfo.getPageNum());
            System.out.println("总页数" + zxcustomerPageInfo.getPages());
            System.out.println("页大小" + zxcustomerPageInfo.getSize());
            System.out.println("总记录数" + zxcustomerPageInfo.getTotal());
            System.out.println("当前页数据" + zxcustomerPageInfo.getList());

            return zxcustomerPageInfo;
        }
    }

    @Override
    public void addcustomer(Zxcustomer zxcustomer) {
        zx_customerMapper.add(zxcustomer);
    }

    @Override
    public void updatecustomer(Zxcustomer zxcustomer) {
        zx_customerMapper.update(zxcustomer);
    }

    @Override
    public void deletecustomer(Integer customer_num) {
        zx_customerMapper.delete(customer_num);
    }

    @Override
    public void deletescustomer(List<Integer> ids) {
        for (Integer id : ids) {
            // 进行删除操作，可以调用你的删除方法
            zx_customerMapper.Deletes(id);
        }
    }

    @Override
    public List<Zxloss> losscustomer() {

        return zx_customerMapper.loss();
    }

    @Override
    public PageInfo lossfindByPage(Integer pageNum, Integer pageSize, String customerName) {
        Page<Zxcustomer> page = PageHelper.startPage(pageNum, pageSize);
        //查询出来所有内容，会根据上面设置的分页参数显示
        if (customerName != "") {
            customerName = "%" + customerName + "%";
            List<Zxloss> zxlosses = zx_customerMapper.selectloss(customerName);
            PageInfo<Zxloss> zxcustomerPageInfo = new PageInfo<>(zxlosses);
            System.out.println("当前页" + zxcustomerPageInfo.getPageNum());
            System.out.println("总页数" + zxcustomerPageInfo.getPages());
            System.out.println("页大小" + zxcustomerPageInfo.getSize());
            System.out.println("总记录数" + zxcustomerPageInfo.getTotal());
            System.out.println("当前页数据" + zxcustomerPageInfo.getList());

            return zxcustomerPageInfo;
        } else {
            List<Zxloss> zxlosses = zx_customerMapper.loss();
            PageInfo<Zxloss> lossPageInfo = new PageInfo<>(zxlosses);
            System.out.println("当前页" + lossPageInfo.getPageNum());
            System.out.println("总页数" + lossPageInfo.getPages());
            System.out.println("页大小" + lossPageInfo.getSize());
            System.out.println("总记录数" + lossPageInfo.getTotal());
            System.out.println("当前页数据" + lossPageInfo.getList());

            return lossPageInfo;
        }
    }

    @Override
    public void updateloss(Zxloss zxloss) {
        zx_customerMapper.updateloss(zxloss);
    }

    @Override
    public void deleteloss(Integer customer_id) {
        zx_customerMapper.deleteloss(customer_id);
    }

    @Override
    public void deletelosses(List<Integer> loss_ids) {
        for (Integer loss_id : loss_ids) {
            // 进行删除操作，可以调用你的删除方法
            zx_customerMapper.deletelosses(loss_id);
        }
    }

    @Override
    public void addloss(Zxloss zxloss) {
        zx_customerMapper.addloss(zxloss);
    }
}
